package TOOLS;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JTextField;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;

public class borderField extends JTextField {
	/**
	 * 
	 */
	private static final long serialVersionUID = -1278750504095761640L;
	public String iTitle="-";
	public String golden="";
	TitledBorder iTBorder=BorderFactory.createTitledBorder(iTitle);
	Font iFont;
	Color titleColor;
	
	public borderField() {
		iTBorder=BorderFactory.createTitledBorder(iTitle);
		this.setBorder(iTBorder);
	}
	
	public void setBounds(int x, int y, int width, int height) {
		super.setBounds(x, y, width, height);
		iFont=new Font("",0,(int)(1.0*height/77*24+1));
		this.setFont(iFont);
		Font tFont=new Font("",1,(int)(1.0*height/77*19+1));
		iTBorder.setTitleFont(tFont);
		this.setBorder(iTBorder);
	}
	
	public void setSize(int width, int height) {
		super.setSize(width, height);
		iFont=new Font("",0,(int)(1.0*height/77*24+1));
		this.setFont(iFont);
		Font tFont=new Font("",1,(int)(1.0*height/77*19+1));
		iTBorder.setTitleFont(tFont);
		this.setBorder(iTBorder);
	}
	
	public void checkGolden() {
		String str=this.getText();
		if(golden.equals(str)) {
			setBorderColor(Color.GREEN);
		}else {
			setBorderColor(Color.RED);
		}
	}
	
	public void setGolden(String newGolden) {
		golden=newGolden;
	}
	
	public String getGolden() {
		return golden;
	}
	
	public void setItitle(String newTitle) {
		iTitle=newTitle;
		iTBorder=BorderFactory.createTitledBorder(iTitle);
		this.setBorder(iTBorder);
	}
	
	public String getItitle() {
		return iTitle;
	}
	
	public void setTitleColor(Color icolor) {
		titleColor=icolor;
		iTBorder.setTitleColor(titleColor);
	}
	
	public void setBorderColor(Color icolor) {
		iTBorder.setBorder(new LineBorder(icolor));
		this.setBorder(iTBorder);
	}
}
